<template>
    <div ref="body">
        <Form :label-width="120" inline>
            <Form-item label="属地区划:">
                <area-linkage :areaCode.sync="queryParam.ssdc0009"></area-linkage>
            </Form-item>
            <Form-item label="救助年月">
                <DatePicker type="month" style="width:150px" v-model="queryParam.acay0003" :editable="false" format="yyyy-MM"/>
            </Form-item>
            <FormItem label="救助对象类别">
                <Select v-model="queryParam.ssdc0010" style="width: 200px" clearable>
                    <Option value="1010">城市最低生活保障对象</Option>
                    <Option value="1020">城市低保边缘家庭</Option>
                    <Option value="1030">农村最低生活保障对象</Option>
                    <Option value="1040">农村低保边缘家庭</Option>
                </Select>
            </FormItem>

            <span v-if="show">
                <Form-item label="被救助人姓名:">
                <Input v-model="queryParam.ssdc0003" placeholder="" style="width:200px"/>
            </Form-item>

            <Form-item label="身份证号码:">
                <Input v-model="queryParam.ssdc0004" placeholder="" style="width:200px"/>
            </Form-item>
            <Form-item label="性别：">
                <dictSelect dictCode="sex" :bindData.sync="queryParam.ssdc0005"
                            style="width: 100px"/>
            </Form-item>
                <Form-item label="出生日期:">
                <DatePicker type="daterange" split-panels v-model="queryParam.ssdc0006_time"
                            placeholder="" style="width: 200px"  :editable="false"></DatePicker>
            </Form-item>
            <Form-item label="年龄:">
                <InputNumber v-model="queryParam.age_begin" :min="0" placeholder="" style="width:93px"/>
                ~
                <InputNumber v-model="queryParam.age_end" :min="0" placeholder="" style="width:93px"/>
            </Form-item>
            <Form-item label="健康状况:">
                <c-dict-select v-model="queryParam.ssdc0008" dictCode="health"
                               placeholder="请选择健康状况"/>
            </Form-item>
            <Form-item label="救助时间:">
                <DatePicker type="daterange" split-panels v-model="queryParam.ssdc0011_time"
                            placeholder="" style="width: 200px"  :editable="false"></DatePicker>
            </Form-item>
            <Form-item label="标准救助金额:">
                <InputNumber v-model="queryParam.ssdc0012_begin" :min="0" placeholder="" style="width:93px"/>
                ~
                <InputNumber v-model="queryParam.ssdc0012_end" :min="0" placeholder="" style="width:93px"/>
            </Form-item>
            <Form-item label="增发救助金额:">
                <InputNumber v-model="queryParam.ssdc0013_begin" :min="0" placeholder="" style="width:93px"/>
                ~
                <InputNumber v-model="queryParam.ssdc0013_end" :min="0" placeholder="" style="width:93px"/>
            </Form-item>
            <Form-item label="总救助金额:">
                <InputNumber v-model="queryParam.ssdc0014_begin" :min="0" placeholder="" style="width:93px"/>
                ~
                <InputNumber v-model="queryParam.ssdc0014_end" :min="0" placeholder="" style="width:93px"/>
            </Form-item>
            <Form-item label="是否确认:">
                <c-dict-select v-model="queryParam.ssdc0027" dictCode="yesorno" style="width:100px"
                               placeholder=""/>
            </Form-item>
            </span>
            <div style="display: inline-block;cursor:pointer" @click="showHidden">
                <template v-if="show">
                    <Form-item label="收起条件" style="cursor:pointer">
                        <div class="ivu-form-item">
                        <span class="ivu-input-suffix">
                          <Icon type="ios-arrow-up"/>
                        </span>
                        </div>
                    </Form-item>
                </template>
                <template v-else>
                    <Form-item label="展开条件" style="cursor:pointer">
                        <div class="ivu-form-item">
                        <span class="ivu-input-suffix">
                            <Icon type="ios-arrow-down"/>
                        </span>
                        </div>
                    </Form-item>
                </template>
            </div>
            <Row class="button_row">
                <span style="float: left;">
                  <Button type="primary" icon="ios-undo" @click="dataConfirm">数据确认</Button>
                </span>
                <span style="float: right;">
                 <Button type="primary" @click="searchQueryNew">查询</Button>
                 <Button type="primary" class="button_item_left" @click="searchResetNew">重置</Button>
                     </span>
            </Row>
        </Form>
        <div id="statistics">
            <span>查询统计:</span>
            <span> 两节救助对象总户数 [ {{statistics.familyNum}} ] 户</span>
            <span>  总救助金额 [ {{statistics.totalMoney}} ]  元</span>
        </div>
        <div>
            <Modal v-model="visibleDetail" title="两节救助数据详情" width="800" style="position:relative;">
                <Form ref="formData" :model="formData" :label-width="150" >
                    <table>
                        <tr>
                            <td>
                                <FormItem label="救助年度" prop="ssdc0001">
                                    <Input v-model="formData.ssdc0001" placeholder="" style="width: 200px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="救助节日" prop="ssdc0002">
                                    <dictSelect :disabled="disabledDetail" :sel_val='formData.ssdc0002'
                                                dictCode="festival" :bindData.sync="queryParam.ssdc0002"
                                                style="width: 200px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="被救助人姓名" prop="ssdc0003">
                                    <Input v-model="formData.ssdc0003" placeholder="" style="width: 200px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="身份证号" prop="ssdc0004">
                                    <Input v-model="formData.ssdc0004" placeholder="" style="width: 200px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="性别" prop="ssdc0005">
                                    <dictSelect :sel_val='formData.ssdc0005' dictCode="sex" style="width: 200px"
                                                :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="出生日期" prop="ssdc0006">
                                    <DatePicker type="date" v-model="formData.ssdc0006" placeholder="请选择出生日期"
                                                style="width: 200px" :disabled="disabledDetail"   :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="年龄" prop="ssdc0007">
                                    <Input v-model="formData.ssdc0007" placeholder="" style="width: 200px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="健康状况" prop="ssdc0008">
                                    <dictSelect :sel_val='formData.ssdc0008' dictCode="health" style="width: 200px"
                                                :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="家庭住址" prop="ssdc0021">
                                    <Input v-model="formData.ssdc0021" placeholder="" style="width: 550px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="联系电话" prop="ssdc0022">
                                    <Input v-model="formData.ssdc0022" placeholder="" style="width: 200px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="救助对象类别" prop="ssdc0010">
                                    <dictSelect :sel_val='formData.ssdc0010' dictCode="systemsubtype"
                                                style="width: 200px" :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="救助时间" prop="ssdc0011">
                                    <DatePicker type="date" v-model="formData.ssdc0011"
                                                style="width: 200px" :disabled="disabledDetail"   :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="标准救助金额" prop="ssdc0012">
                                    <Input v-model="formData.ssdc0012" placeholder="" style="width: 200px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="增发救助金额" prop="ssdc0013">
                                    <Input v-model="formData.ssdc0013" placeholder="" style="width: 200px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="总救助金额" prop="ssdc0014">
                                    <Input v-model="formData.ssdc0014" placeholder="" style="width: 200px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="开户行" prop="ssdc0025">
                                    <dictSelect :sel_val='formData.ssdc0025' dictCode="bankcategory"
                                                style="width: 200px" :disabled="disabledDetail"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="银行账号" prop="ssdc0023">
                                    <Input v-model="formData.ssdc0023" placeholder="" style="width: 200px"
                                           :disabled="disabledDetail"/>
                                </FormItem>
                            </td>

                        </tr>
                    </table>
                </Form>
                <div slot="footer">
                    <Button @click="visibleDetail = false">关闭</Button>
                </div>
            </Modal>
        </div>
        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :radio-config="{highlight: true}"
                       @cell-click="selectChange"
                       :data="tableData">
                <vxe-table-column type="radio" width="60" align="center" fixed="left"/>
                <vxe-table-column field="ssdc0001" title="救助年度" align="center" width="100" fixed="left"/>
                <vxe-table-column field="ssdc0009_name" title="属地区划" align="center" width="230" fixed="left"/>
                <vxe-table-column field="ssdc0003" title="被救助人姓名" align="center" width="110" fixed="left"/>
                <vxe-table-column field="ssdc0004" title="身份证号" align="center" width="160"/>
                <vxe-table-column field="ssdc0027_name" title="是否确认" align="center" width="80"/>
                <vxe-table-column field="ssdc0011" title="救助时间" align="center" width="140" :formatter="renderTime"/>
                <vxe-table-column field="ssdc0002_name" title="救助节日" align="center" width="160"/>
                <vxe-table-column field="ssdc0005_name" title="性别" align="center" width="80"/>
                <vxe-table-column field="ssdc0006" title="出生日期" align="center" width="120" :formatter="renderTime"/>
                <vxe-table-column field="ssdc0007" title="年龄" align="center" width="70" :formatter="formartAge"/>
                <vxe-table-column field="ssdc0008_name" title="健康状况" align="center" width="140"/>
                <vxe-table-column field="ssdc0010_name" title="救助对象类别" align="center" width="140"/>
                <vxe-table-column field="ssdc0012" title="标准救助金额" align="center" width="110"/>
                <vxe-table-column field="ssdc0013" title="增发救助金额" align="center" width="110"/>
                <vxe-table-column field="ssdc0014" title="总救助金额" align="center" width="100"/>
                <vxe-table-column field="ssdc0023" title="银行账号" align="center" width="160"/>
                <vxe-table-column field="ssdc0025_name" title="开户行" align="center" width="140"/>
                <vxe-table-column title="操作" align="center" width="180" fixed="right">
                    <template #default="{row}">
                        <Button type="default" @click="searchDetail(row)">详情</Button> &nbsp;
                        <Button type="error" @click="handleDelete(row)">删除</Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
    </div>
</template>

<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import {postAction} from '@/api/request'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'
    import DateFormat from '@/plugins/format.js'


    export default {
        name: "ss13003list",
        components: {dictSelect},
        mixins: [CommonMixin],
        data() {
            return {
                disabledDetail: true,
                visibleDetail: false,
                formData: {},
                statistics: {
                    familyNum: 0,
                    totalMoney: 0,
                },
                queryParam: {
                    age_begin: null,
                    age_end: null,
                    ssdc0012_begin: null,
                    ssdc0012_end: null,
                    ssdc0013_begin: null,
                    ssdc0013_end: null,
                    ssdc0014_begin: null,
                    ssdc0014_end: null,
                },
                Loading: false,
                show: false,
                selectRow: null,
                url: {
                    list: "/api/ac/subsistence/ss13003Service/getPageList",
                    dataConfirm: "/api/ac/subsistence/ss13003Service/createConfirmAllData",
                    delete: "/api/ac/subsistence/ss13003Service/deleteData",
                },
                dictList: [],
            }
        },
        methods: {
            dataConfirm() {
                //数据确认let
                let ssdc0010 = this.queryParam.ssdc0010;
                let ssdc0011 = this.queryParam.acay0003;
                if (ssdc0010 == undefined|| ssdc0010 =='') {
                    this.$Message.error("请选择需要确认数据的救助对象类别");
                    return;
                }
                if (ssdc0011 == undefined || ssdc0011 =='') {
                    this.$Message.error("请选择需要确认数据的发放年月");
                    return;
                }
                let param = {};
                let url = this.url.dataConfirm;
                param.ssdc0010 = ssdc0010;
                param.ssdc0011 = ssdc0011;
                postAction(url, param).then((res) => {
                    console.log("res: ", res)
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        this.$Message.success(res.data.data.msg);
                        this.searchQueryNew();
                    }
                }).finally(() => {
                    this.Loading = false;
                })
            },
            showHidden() {
                this.show = !this.show;
            },
            formartAge(h) {
                if (h.cellValue) {
                    return Number(h.cellValue);
                }
            },
            selectChange({row}) {
                this.$refs.xTree.setRadioRow(row);
                this.selectRow = row;
            },
            clearRadioRowEevnt() {
                this.selectRow = null
                this.$refs.xTree.clearRadioRow()
            },
            searchQueryNew() {
                var time = this.queryParam.ssdc0001;
                if (time) {
                    this.queryParam.ssdc0001 = this.DateFormat(time, 'YYYY')
                    this.queryParam.ssdc0011 = this.DateFormat(time, 'YYYY-MM')
                }
                var ssdc0006_time = this.queryParam.ssdc0006_time;
                if (ssdc0006_time) {
                    if (ssdc0006_time[0]) {
                        this.queryParam.ssdc0006_begin = this.DateFormat(ssdc0006_time[0], 'YYYY-MM-DD') + " 00:00:00";
                    }
                    if (ssdc0006_time[1]) {
                        this.queryParam.ssdc0006_end = this.DateFormat(ssdc0006_time[1], 'YYYY-MM-DD') + " 23:59:59";
                    }
                }
                var ssdc0011_time = this.queryParam.ssdc0011_time;
                if (ssdc0011_time) {
                    if (ssdc0011_time[0]) {
                        this.queryParam.ssdc0011_begin = this.DateFormat(ssdc0011_time[0], 'YYYY-MM-DD') + " 00:00:00";
                    }
                    if (ssdc0011_time[1]) {
                        this.queryParam.ssdc0011_end = this.DateFormat(ssdc0011_time[1], 'YYYY-MM-DD') + " 23:59:59";
                    }
                }
                this.loadData(1);
                this.queryParam.ssdc0001 = time;
            },
            searchResetNew() {
                this.queryParam = {};
                this.queryParam.age_begin = null;
                this.queryParam.age_end = null;
                this.queryParam.ssdc0012_begin = null,
                this.queryParam.ssdc0012_end = null,
                this.queryParam.ssdc0013_begin = null,
                this.queryParam.ssdc0013_end = null,
                this.queryParam.ssdc0014_begin = null,
                this.queryParam.ssdc0014_end = null,
                this.clearRadioRowEevnt();
                this.loadData(1);
            },
            loadData(arg) {
                if (arg == 1) {
                    this.pageNo = 1;
                }
                let that = this;
                that.Loading = true;
                if (this.queryParam.acay0003 != '' && this.queryParam != undefined){
                    this.queryParam.acay0003 = this.DateFormat(this.queryParam.acay0003, 'YYYY-MM');
                }
                let param = Object.assign({}, this.queryParam);
                let url = this.url.list;
                param.pageNo = this.pageNo;
                param.pageSize = this.pageSize;
                postAction(url, param).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        that.tableData = res.data.data.results;
                        that.dataCount = res.data.data.totalRecord;
                        that.statistics.familyNum = res.data.data.params.familyNum;
                        that.statistics.totalMoney = res.data.data.params.totalMoney;
                    }
                }).finally(() => {
                    that.Loading = false;
                })
            }
            ,
            searchDetail(row) {
                const that = this;
                let record = row;
                if (record.id) {
                    that.visibleDetail = true
                    that.formData = Object.assign({}, record)
                    if (that.formData.ssdc0007) {
                        that.formData.ssdc0007 = Number(record.ssdc0007);
                    }
                    if (that.formData.ssdc0006) {
                        that.formData.ssdc0006 = new Date(record.ssdc0006);
                    }
                    if (that.formData.ssdc0011) {
                        that.formData.ssdc0011 = new Date(record.ssdc0011);
                    }
                } else {
                    that.visibleDetail = false
                }
            },
            handleDelete(row) {
                let that = this;
                if (row.ssdc0027 == '1'){
                    that.$Message.error('数据已确认, 不允许删除');
                    return
                }else{
                    this.$Modal.confirm({
                        title: '确定删除吗？',
                        onOk: () => {
                            if (!this.url.delete) {
                                this.$Message.error("请设置url.delete属性!")
                                return
                            }
                            let param = {id:row.ID}
                            postAction(that.url.delete,param ).then((res) => {
                                if (res.data.errcode == 0) {
                                    that.$Message.success("删除成功！");
                                } else {
                                    that.$Message.error(res.data.errmsg);
                                }
                                that.searchQueryNew();
                            });
                        }
                    })
                }
            },
            modalFormOk() {
                this.selectRow = null;
                // 新增/修改 成功时，重载列表
                this.loadData();
            },
        },
        created() {
            this.loadData();
        }

    }
</script>

<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }

    /deep/ .ivu-upload-list {
        display: none;
    }

    /deep/ .ivu-table-cell {
        padding-right: 0px;
        padding-left: 0px;
    }

    /deep/ .ivu-form-item {
        margin-bottom: 10px;
    }

    #statistics {
        height: 50px;
        line-height: 50px;
        width: 100%;
        color: red;
        font-size: 16px;
    }

    #statistics span {
        padding-left: 10px;
        padding-right: 10px;
    }

</style>
